package com.fary.runlistener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

public class MyApplicationRunListener implements SpringApplicationRunListener {

    /**
     * 获取日志对象，构造函数传入当前类，查找日志方便定位
     * @Slf4j
     */
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    private final SpringApplication application;
    private final String[] args;

    public MyApplicationRunListener(SpringApplication sa, String[] args) {
        this.application = sa;
        this.args = args;
    }

    @Override
    public void starting() {
        log.info("SpringApplicationRunListener的starting方法...");
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
        log.info("SpringApplicationRunListener的environmentPrepared方法...");
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        log.info("SpringApplicationRunListener的contextPrepared方法...");
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        log.info("SpringApplicationRunListener的contextLoaded方法...");
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        log.info("SpringApplicationRunListener的running方法...");
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        log.info("SpringApplicationRunListener的failed方法...");
    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        log.info("SpringApplicationRunListener的started方法...");
    }
}
